package anonymouschat.security;

import java.io.Serializable;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Stores a mapping of user names to salt. Salt is used when creating an AES key
 * for password based authentication
 * <br/><br/>
 * When saved as a file, this class does not need to be password protected
 * because it only contains half the secert, and the user is suppose to keep
 * their half in their head
 * 
 * @author jnfrye
 * 
 */
public class NameSaltPairs implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1401777585147197085L;


	/**
	 * Pairs of user names and their respective slat values
	 */
	private ConcurrentHashMap<String, KeySalt> pairing = new ConcurrentHashMap<String, KeySalt>();

	public NameSaltPairs() {

	}

	/**
	 * Add a user to this the object, along with their salt values
	 * @param u
	 * @param salt
	 */
	public void addPair(String u, KeySalt salt) {
		this.pairing.put(u, salt);
	}

	public KeySalt getUserSalt(String u) {
		return this.pairing.get(u);
	}

	/**
	 * Get all the user names stored in this file
	 * 
	 * @return
	 */
	public String[] getUserNames() {
		Set<String> users = this.pairing.keySet();
		String[] ret = new String[users.size()];
		int i = 0;
		for (String u : users) {
			ret[i] = u;
			i++;
		}
		return ret;
	}

}
